﻿using System;
using System.Collections.Generic;
using System.Text;
using kxjsj.Model;
using Microsoft.ApplicationBlocks.Data;
using System.Data.OleDb;
using System.Data;
using System.IO;

namespace kxjsj
{
    class Access
    {
        public static void ExportInfo(OleDbConnection con, string inner_id)
        {
            string errorMessage = string.Empty;
            string projectSql = "select name, main_author, main_unit, unit1_contact, unit1_phone, unit1_mobile, result_reg_id, level1_major, level2_major, " +
                "tech_area, award_type, subject, pro_source1, pro_source2, touru1, touru2, pro_year, sec_level, start_time, end_time, " +
                "IsPublish, Introduction, Innovation, Content, AppIntro, AppUnit, Social, Economic, Finance, FinancePhone, " +
                "ChartTitle1, ChartPath1, ChartTitle2, ChartPath2, otherTouru, ContentImage1, ContentImage2, ContentImage3, ContentImage4, ContentImage5, ContentImage6, ContentImage7, ContentImage8, ContentType " +
                "from project where inner_id = '" + inner_id + "'";
            DataTable dt = SqlHelper.ExecuteDataset(con, CommandType.Text, projectSql).Tables[0];

        }

        public static void CompactAccessDB(string FromDB, string ToDB)
        {
            try
            {
                JRO.JetEngine jro;
                jro = new JRO.JetEngine();
                File.Delete(ToDB);
                jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FromDB, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ToDB + ";Jet OLEDB:Engine Type=5");
                File.Copy(ToDB, FromDB, true);
                //File.Delete(ToDB);
                //MsgBox(ToDB);
            }
            catch (System.Exception CompactAccessDB_Err)
            {
                throw CompactAccessDB_Err;
            }
        }

        private void SaveProject()
        {

        }

        private void InsertProject(OleDbConnection con, string inner_id, ref string errorMessage)
        {
            Project project = PDFCreator.GetProject(inner_id, ref errorMessage);

            List<OleDbParameter> paramList = new List<OleDbParameter>();
            paramList.Add(new OleDbParameter("@id", "1"));
            paramList.Add(new OleDbParameter("@inner_id", inner_id));
            paramList.Add(new OleDbParameter("@ProName", project.Name));
            paramList.Add(new OleDbParameter("@ResultRegId", project.ResultRegId));
            paramList.Add(new OleDbParameter("@Level1Major", project.Level1Major));
            paramList.Add(new OleDbParameter("@Level2Major", project.Level2Major));
            paramList.Add(new OleDbParameter("@TechArea", project.TechArea));
            paramList.Add(new OleDbParameter("@AwardType", project.AwardType));
            paramList.Add(new OleDbParameter("@Subject", project.Subject));
            paramList.Add(new OleDbParameter("@ProSource1", project.ProSource1));
            paramList.Add(new OleDbParameter("@Touru1", project.PlanTouru));
            paramList.Add(new OleDbParameter("@ProSource2", project.Pipei));
            //paramList.Add(new OleDbParameter("@Touru2", project.Touru2));
            paramList.Add(new OleDbParameter("@OtherTouru", project.OtherTouru));
            //paramList.Add(new OleDbParameter("@ProYear", project.ProYear));
            paramList.Add(new OleDbParameter("@SecLevel", project.SecLevel));
            paramList.Add(new OleDbParameter("@StartTime", project.StartTime));
            //paramList.Add(new OleDbParameter("@Year", project.ProYear));
            paramList.Add(new OleDbParameter("@EndTime", project.EndTime));
            paramList.Add(new OleDbParameter("@Introduction", project.Introduction));
            paramList.Add(new OleDbParameter("@IsPublish", project.IsPublish));
            paramList.Add(new OleDbParameter("@Innovation", project.Innovation));
            paramList.Add(new OleDbParameter("@Content", project.Content));
            paramList.Add(new OleDbParameter("@AppIntro", project.AppIntro));
            paramList.Add(new OleDbParameter("@Social", project.Social));
            paramList.Add(new OleDbParameter("@Economic", project.Economic));
            paramList.Add(new OleDbParameter("@AppUnit", project.AppUnit));
            paramList.Add(new OleDbParameter("@Finance", project.Finance));
            paramList.Add(new OleDbParameter("@FinancePhone", project.FinancePhone));
            paramList.Add(new OleDbParameter("@ContentType", project.ContentType));

            string sql = "insert into project (id, inner_id, name, result_reg_id, level1_major, level2_major, tech_area, award_type, subject, pro_source1, touru1, pro_source2, touru2, pro_year" +
                            "sec_level, start_time, year, end_time, Introduction, IsPublish, Innovation, Content, AppIntro," +
                            " Social, Economic, ChartTitle1, ChartPath1, ChartTitle2, ChartPath2, AppUnit, Finance, FinancePhone, " +
                            " otherTouru, pro_source, ContentImage1, ContentImage2, ContentImage3, ContentImage4, ContentImage5, ContentImage6, ContentImage7," +
                            " ContentImage8, ContentType) " +
                            "values (@id, @inner_id, @name, @result_reg_id, @level1_major, @level2_major, @tech_area, @award_type, @subject, @pro_source1, @touru1, @pro_source2, @touru2, @pro_year, " +
                            "@sec_level, @start_time,@year,  @end_time, @award_year, @fill_time, @tj_award_level, @recommend_unit, @problem, @recommend_order, @submit_date, " +
                            "@export_time, @recommend, @ylwb3, @ylwb4, @recommend_remark, @ylbz2, @ylbz3, @ylbz4, @Introduction, @IsPublish, @Innovation, @Content, @AppIntro, " +
                            "@Social, @Economic, @ChartTitle1, @ChartPath1, @ChartTitle2, @ChartPath2, @AppUnit, @Finance, @FinancePhone, " +
                            "@otherTouru, @pro_source, @ContentImage1, @ContentImage2, @ContentImage3, @ContentImage4, @ContentImage5, @ContentImage6, @ContentImage7, " +
                            "@ContentImage8, @ContentType)";

            SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, paramList.ToArray());

        }
    }
}
